﻿@using Orchard.ContentManagement;

@*doing excerpt generation on the way out for now so we don't stick ourselves with needing to regen excerpts for existing data
  also, doing this here, inline, until we have a pluggable processing model (both in and out)
  also, ...this is ugly *@
@{ 
    var blogPost = Model.ContentItem;
    
    string bodyHtml = Model.Html.ToString();
    var body = new HtmlString(Html.Excerpt(bodyHtml, 500).ToString().Replace(Environment.NewLine, "</p>" + Environment.NewLine + "<p>"));

    var firstIMG = bodyHtml.IndexOf("<img");
    var firstSlashIMG = bodyHtml.IndexOf("/>", firstIMG >= 0 ? firstIMG : 0);

    if (firstIMG >= 0 && firstSlashIMG > firstIMG) {
        bodyHtml = bodyHtml.Substring(firstIMG, firstSlashIMG + 2 - firstIMG);
        

            bodyHtml = bodyHtml.Replace("<img", "<img class=\"img-responsive\"");
      
    }

    var firstImage = new HtmlString(bodyHtml);
}


     @if (firstIMG >= 0 && firstSlashIMG > firstIMG) {
        <a href="@Url.ItemDisplayUrl((IContent)blogPost)">@firstImage</a>
    
}

<p>@body</p>
<a href="@Url.ItemDisplayUrl((IContent)blogPost)" class="btn btn-sm btn-primary">Read more</a>